package com.health.work.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import com.health.work.model.BusinessBean;
import com.health.work.model.Doctorbean;

import android.content.Context;
import android.util.Log;

public class RequestParamtersUtil {

	private WebServiceUtils mWebServiceUtils;
	// 检查日期列表
	private static ArrayList LIST_CHECKDATE;
	// 最近一次检查日期
	private static String LASTCHECKDATE = "1900-01-01";
	private static final String SERVER_NAMESPACE = "http://cnhealth.cn/";
	private static final String FUC_GETEHR = "GetEHR";
	private static final String SOAP_ACTION = "http://cnhealth.cn/";
	private static final String SERVER_URL = "http://mc.cnhealth.cn:81/TestAndroidService/Service.asmx";
	 private static final String FUC_GETITEMS = "GetItems";
	 // 体检项目
	    private static String [] EHRItems;
	    
    public static String[] getEHRItems() {
        return EHRItems;
    }

    public static void setEHRItems(String[] eHRItems) {
        EHRItems = eHRItems;
    }
   


    public static String getLASTCHECKDATE() {
        return LASTCHECKDATE;
    }

    public static void setLASTCHECKDATE(String lASTCHECKDATE) {
        LASTCHECKDATE = lASTCHECKDATE;
    }

    
    public static ArrayList getLIST_CHECKDATE() {
        return LIST_CHECKDATE;
    }

    public static void setLIST_CHECKDATE(ArrayList lIST_CHECKDATE) {
        LIST_CHECKDATE = lIST_CHECKDATE;
    }
	
	public RequestParamtersUtil() {
		super();
		mWebServiceUtils = new WebServiceUtils();
	}

	/**
	 * 登录注册的url 对应的接口实现
	 */
	// 修改密码
	public void UpdatePassWord(String MobilePhone, String PassWord,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"UpdatePassWord");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("PassWord", PassWord);
		Log.e("UpdatePassWord", "MobilePhone: " + MobilePhone + "  PassWord:"
				+ PassWord);
		mWebServiceUtils.sendRequest(rpc, "UpdatePassWord",
				HEALTHPASSPORT.URL_MEMBER, data);
	}

	// 登录
	public void Login(String MobilePhone, String PassWord, String deviceId,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "Login");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("PassWord", PassWord);
		// rpc.addProperty("deviceId", deviceId);
		Log.e("Login", "MobilePhone: " + MobilePhone + "  PassWord:" + PassWord);
		mWebServiceUtils.sendRequest(rpc, "Login", HEALTHPASSPORT.URL_MEMBER,
				data);
	}

	// 用户反馈
	public void postFeedBack(String contactWay, String content,
			String mobilephone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.URL_FEEDBACK, "feedback");
		rpc.addProperty("contactWay", contactWay);
		rpc.addProperty("content", content);
		rpc.addProperty("mobilephone", mobilephone);
		mWebServiceUtils.sendRequest(rpc, "feedback",
				HEALTHPASSPORT.URL_FEEDBACK, data);
	}

	// 注册第一步
	public void Registration(String MobilePhone, String PassWord,
			String Quipmentid, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"Registration");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("PassWord", PassWord);
		rpc.addProperty("quipmentid", Quipmentid);
		Log.e("Registration", "MobilePhone: " + MobilePhone + "  PassWord:"
				+ PassWord + " quipmentid:" + Quipmentid);
		mWebServiceUtils.sendRequest(rpc, "Registration",
				HEALTHPASSPORT.URL_MEMBER, data);
	}

	// 注册 成为档案会员
	public void RegistrationWithIDNumber(String IDNumber, String Name,
			String MobilePhone,String Photo, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"RegistrationWithIDNumber");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Name", Name);
		rpc.addProperty("IDNumber", IDNumber);
		rpc.addProperty("Photo", Photo);
		mWebServiceUtils.sendRequest(rpc, "RegistrationWithIDNumber",
				HEALTHPASSPORT.URL_MEMBER, data);
	}

	// （注册成为医师
	public void Save(Doctorbean doctor, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "Save");
		rpc.addProperty("Province", doctor.Province);
		rpc.addProperty("City", doctor.City);
		rpc.addProperty("CountyArea", doctor.CountyArea);
		rpc.addProperty("Township", doctor.Township);
		rpc.addProperty("CertificateTypeId", doctor.CertificateTypeId);
		rpc.addProperty("ProfessionalCategoryId", doctor.ProfessionalCategoryId);
		rpc.addProperty("Name", doctor.Name);
		rpc.addProperty("Sex", doctor.Sex);
		rpc.addProperty("photo", doctor.photo);
		rpc.addProperty("MobilePhone", doctor.MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "Save", HEALTHPASSPORT.URL_MEMBER,
				data);
	}

	// 分享
	public void AddIntegral(Context mContext, String Integral,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "AddIntegral");
		String MobilePhone = UserInfoUtils.getUserProperty(mContext,
				HEALTHPASSPORT.MOBILEPHONE);
		if ("".equals(MobilePhone)) {
			return;
		}
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Integral", Integral);
		Log.e("AddIntegral", "MobilePhone: " + MobilePhone + "  Integral:"
				+ Integral);
		mWebServiceUtils.sendRequest(rpc, "AddIntegral",
				HEALTHPASSPORT.URL_MEMBER, data);
	}

	// 根据id查找当前记录
	public void GetMemberById(String Id, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetMemberById");
		rpc.addProperty("Id", Id);
		Log.e("GetMemberById", "Id: " + Id);
		mWebServiceUtils.sendRequest(rpc, "GetMemberById",
				HEALTHPASSPORT.URL_FEEDBACK, data);
	}

	// 根据MobilePhone查找当前记录
	public void GetMemberByMobilePhone(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetMemberByMobilePhone");
		rpc.addProperty("MobilePhone", MobilePhone);
		Log.e("GetMemberByMobilePhone", "MobilePhone: " + MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetMemberByMobilePhone",
				HEALTHPASSPORT.URL_FEEDBACK, data);
	}

	/**
	 * 反馈的url 对应的接口实现
	 */
	// 反馈
	public void FeedbackContent(Context mContext, String contactWay,
			String content, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"FeedbackContent");
		rpc.addProperty("contactWay", contactWay);
		rpc.addProperty("content", content);
		rpc.addProperty("mobilephone", UserInfoUtils.getUserProperty(mContext,
				HEALTHPASSPORT.MOBILEPHONE));//
		Log.e("FeedbackContent", "contactWay: " + contactWay + "  content:"
				+ content);
		mWebServiceUtils.sendRequest(rpc, "FeedbackContent",
				HEALTHPASSPORT.URL_FEEDBACK, data);
	}

	/**
	 * 地址的url 对应的接口实现
	 */

	// 根据Id获取地址
	public void GetById(String id, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "GetById");
		rpc.addProperty("id", id);
		mWebServiceUtils.sendRequest(rpc, "GetById", HEALTHPASSPORT.URL_AREA,
				data);
	}

	// 根据父级Id获取子集地址
	public void GetByUpId(String upid, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "GetByUpId");
		rpc.addProperty("upid", upid);
		mWebServiceUtils.sendRequest(rpc, "GetByUpId", HEALTHPASSPORT.URL_AREA,
				data);
	}

	/**
	 * 商家的url 对应的接口实现
	 */
	// 根据Id获取商家类别
	public void GetById(int id, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "GetById");
		rpc.addProperty("id", id);
		mWebServiceUtils.sendRequest(rpc, "GetById",
				HEALTHPASSPORT.URL_BUSINESS_TYPE_SERVICE, data);
	}

	// 商家注册保存信息
	public void SaveBusiness(BusinessBean business, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SaveBusiness");
		rpc.addProperty("Province", business.Province);
		Log.e("Province", business.Province+"  "+business.City+"  "+business.CountyArea+"  "+business.Township);
		rpc.addProperty("City", business.City);
		rpc.addProperty("CountyArea", business.CountyArea);
		rpc.addProperty("Township", business.Township);
		rpc.addProperty("BusinessTypeId", business.BusinessTypeId);
		Log.e("BusinessTypeId", business.BusinessTypeId+" MainCommodities "+business.MainCommodities+"  Name "+business.Name+"  BusinessAddress "+business.BusinessAddress);
		rpc.addProperty("MainCommodities", business.MainCommodities);
		rpc.addProperty("Name", business.Name);
		rpc.addProperty("BusinessAddress", business.BusinessAddress);
		rpc.addProperty("Photo", business.photo);
		rpc.addProperty("MobilePhone", business.MobilePhone);
		Log.e("SaveBusiness", "MobilePhone: " + business.MobilePhone
				+ " photo: " + business.photo);
		mWebServiceUtils.sendRequest(rpc, "SaveBusiness",
				HEALTHPASSPORT.URL_BUSINESS_SERVICE, data);
	}

	/**
	 * 主页面相关 http://60.174.95.24:82/Healthy/ MainService.ashx
	 */
	// 向医生提问

	// 查询医生或专家。参数（省，市，县，乡。专业类别，姓名，是否专家）。“是否专家”字段为“true”或false,
	// 返回值。整条json数据:包括成员表和医护表所有字段.0:无数据
	public void SelectHealthyCare(String Province, String City,
			String CountyArea, String Township, String ProfessionalCategoryId,
			String Name, String IsExpert, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SelectHealthyCare");
		rpc.addProperty("Province", Province);
		rpc.addProperty("City", City);
		rpc.addProperty("CountyArea", CountyArea);
		rpc.addProperty("Township", Township);
		rpc.addProperty("ProfessionalCategoryId", ProfessionalCategoryId);
		rpc.addProperty("Name", Name);
		rpc.addProperty("IsExpert", IsExpert);
		mWebServiceUtils.sendRequest(rpc, "SelectHealthyCare",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 提问,添加问题，增加积分。参数（手机号码，问题内容。角色，分值，医生Id。）。成功返回json字符串，失败返回0.
	public void Questions(String MobilePhone, String Question, String Role,
			String Integral, String HealthyCareMobilePhone,String ProfessionalCategoryId, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "Questions");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Question", Question);
		rpc.addProperty("Role", Role);
		rpc.addProperty("Integral", Integral);
		rpc.addProperty("HealthyCareMobilePhone", HealthyCareMobilePhone);
		rpc.addProperty("ProfessionalCategoryId", ProfessionalCategoryId);
		mWebServiceUtils.sendRequest(rpc, "Questions",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 回复。参数（咨询Id，角色，内容，手机号码）.返回值。成功json字符串。失败。“0”
	public void Reply(String ConsultationId, String Role, String content,String Integral, String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "Reply");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("content", content);
		rpc.addProperty("Role", Role);
		rpc.addProperty("Integral", Integral);
		rpc.addProperty("ConsultationId", ConsultationId);
		mWebServiceUtils.sendRequest(rpc, "Reply",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 评价。参数（咨询Id，评价状态，评价内容）成功返回0，失败返回1.
	public void Evaluation(int ConsultationId, String EvaluationState,
			String Evaluation, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "Evaluation");
		rpc.addProperty("EvaluationState", EvaluationState);
		rpc.addProperty("ConsultationId", ConsultationId);
		rpc.addProperty("Evaluation", Evaluation);
		mWebServiceUtils.sendRequest(rpc, "Evaluation",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 判断是否能提新问题。返回值。1能。2上一个问题未结束。3今日已经提了三个问题
	public void IsQuestions(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "IsQuestions");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "IsQuestions",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 获取问题列表 参数（手机号码）。返回值;json字符串：我的问题列表。“0”无数据.
	public void GetQuestions(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetQuestions");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetQuestions",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 获取问题详细信息 参数（咨询Id）。返回值;json字符串：咨询问题的详细信息。“0”无数据.
	public void GetQuestionDetail(int ConsultationId, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetQuestionDetail");
		rpc.addProperty("ConsultationId", ConsultationId);
		mWebServiceUtils.sendRequest(rpc, "GetQuestionDetail",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
	// 根据专业类别获取问题列表。参数（类别Id）。返回值;json字符串：咨询问题的详细信息。“0”无数据.
		public void GetQuestionsByPCategoryId(int ProfessionalCategoryId, DefaultJSONData data) {
			SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
					"GetQuestionsByPCategoryId");
			rpc.addProperty("ProfessionalCategoryId", ProfessionalCategoryId);
			mWebServiceUtils.sendRequest(rpc, "GetQuestionsByPCategoryId",
					HEALTHPASSPORT.URL_MAINSERVICE, data);
		}

	// 向专家提问
	// 查询托管人."0"尚未托管。“1”待专家确认。json字符串;专家信息
	public void GetTrusteeship(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetTrusteeship");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetTrusteeship",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
//	健康托管."0"失败。"1"成功
	public void Trusteeship(String MobilePhone, String ExpertMobilephone ,DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"Trusteeship");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("ExpertMobilephone", ExpertMobilephone);
		mWebServiceUtils.sendRequest(rpc, "Trusteeship",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
//	托管解除.参数（会员手机号码）"1"失败。“0”数据请求成功
	public void RelieveTrusteeship(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"RelieveTrusteeship ");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "RelieveTrusteeship ",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
//	更新佣金。“0”成功。“1”失败
	public void SetCommission(String MobilePhone,String Commission, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SetCommission");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Commission", Commission);
		mWebServiceUtils.sendRequest(rpc, "SetCommission",
//				HEALTHPASSPORT.URL_MAINSERVICE, data);//老文档的url
				HEALTHPASSPORT.URL_OTHER, data);//新文档中的url
	}
	
//	判断医生是否能升级成专家。若是的话，升级."0"升级成功.“1”升级失败。"2"好评率不足。“3”积分不足
	public void DoctorUpgrade(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"DoctorUpgrade");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "DoctorUpgrade",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
//	托管确认."1"成功。“0”失败。State有两个选择“确认”，“关闭”
	public void ConfirmTrusteeship(String MobilePhone,String ExpertMobilephone,String State, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"ConfirmTrusteeship");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("ExpertMobilephone", ExpertMobilephone);
		rpc.addProperty("State", State);
		mWebServiceUtils.sendRequest(rpc, "ConfirmTrusteeship",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
//	添加病历.参数（病历名称，是否开放（true,或false）,病历说明,图片地址（多个地址以;隔开））.返回值;"0"成功。“1”失败。
	public void SaveMedicalRecord(String MobilePhone,String MedicalName,String IsOpen,String photos,String remark,DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SaveMedicalRecord");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("MedicalName", MedicalName);
		rpc.addProperty("IsOpen", IsOpen);
		rpc.addProperty("photos", photos);
		rpc.addProperty("remark", remark);
		mWebServiceUtils.sendRequest(rpc, "SaveMedicalRecord",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
//	病历是否开放.参数(病历Id，是否开放)。返回值：“0”成功。“1”失败
	public void IsOpen(String MedicalId,String IsOpen,DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"IsOpen");
		rpc.addProperty("MedicalId", MedicalId);
		rpc.addProperty("IsOpen", IsOpen);
		mWebServiceUtils.sendRequest(rpc, "IsOpen",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
//	发布商品。（手机号，商品名称，品质（全新、二手），图片路径，价格）."0"成功。“1”失败
	 public void releaseProduct(String MobilePhone,String Name,String Quality, String Photo, String Price,DefaultJSONData data){
		 SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
					"releaseProduct");
			rpc.addProperty("MobilePhone", MobilePhone);
			rpc.addProperty("Name", Name);
			rpc.addProperty("Quality", Quality);
			rpc.addProperty("Photo", Photo);
			rpc.addProperty("Price", Price);
			mWebServiceUtils.sendRequest(rpc, "releaseProduct",
					HEALTHPASSPORT.URL_MAINSERVICE, data);
	 }
	
	//根据条件查询所有商家。（省市，县，乡镇，商家类别Id，折扣，商家手机号码）。全部参数都可以填“”字符串。返回值。整条json数据:包括商家表和医护表所有字段.0:无数据
	public void SelectBusiness(String Province, String City, String CountyArea,
			String Township, String BusinessTypeId, String Discount,
			String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SelectBusiness");
		rpc.addProperty("Province", Province);
		rpc.addProperty("City", City);
		rpc.addProperty("CountyArea", CountyArea);
		rpc.addProperty("Township", Township);
		rpc.addProperty("BusinessTypeId", BusinessTypeId);
		rpc.addProperty("Discount", Discount);
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "SelectBusiness",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
	// 添加某个商品的关注（若是以前没有关注，关注数加1。若是已关注，则不能再关注），并返回商品信息.参数（产品Id，手机号码）。返回值json.整条产品数据。“1”失败."2"已关注
	public void AddAttentionNum(String productId, String MobilePhone,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"AddAttentionNum");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("productId", productId);
		mWebServiceUtils.sendRequest(rpc, "AddAttentionNum",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 添加某个商品的赞数（若是以前没有赞，赞数加1。若是已赞，则不能再赞），并返回商品信息.参数（产品Id，手机号码）。返回值json.整条产品数据。“1”失败。“2”已经赞过
	public void AddGoodCount(String productId, String MobilePhone,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"AddGoodCount");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("productId", productId);
		mWebServiceUtils.sendRequest(rpc, "AddGoodCount",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}

	// 添加某个商品的预订数和商家的服务人次.参数（产品Id，手机号码，预订数量）."0"成功。“1”失败
	public void AddPreOrder(String productId, String MobilePhone,
			DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "AddPreOrder");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("productId", productId);
		mWebServiceUtils.sendRequest(rpc, "AddPreOrder",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	/**
	 * 主页面商家补充: 
	 */
//	查询符合条件的所有商家发布的所有产品.（省市，县，乡镇，商家类别，折扣，商家手机号码）。全部参数都可以填“”字符串。返回值。整条json数据.0:无数据
	public void SelectProduct(String Province, String City, String CountyArea, String Township, String BusinessTypeId, String Discount, String MobilePhone,DefaultJSONData data){
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SelectProduct");
		rpc.addProperty("Province", Province);
		rpc.addProperty("City", City);
		rpc.addProperty("CountyArea", CountyArea);
		rpc.addProperty("Township", Township);
		rpc.addProperty("BusinessTypeId", BusinessTypeId);
		rpc.addProperty("Discount", Discount);
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "SelectProduct",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
	public void SelectProductById(int id,DefaultJSONData data){
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SelectProductById");
		rpc.addProperty("Id", id);
		mWebServiceUtils.sendRequest(rpc, "SelectProductById",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
	/**
	 * 
	 *  其他角色登陆相关
	 *	http://60.174.95.24:82/Healthy/ Other.asmx
	 */
//		根据手机号码查看医护的信息。参数（手机号码）返回值。整条json数据:包括商家表的所有字段.0:无数据
	public void GetHealthCareByMobilePhone(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetHealthCareByMobilePhone");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetHealthCareByMobilePhone",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
//	根据手机号码查看商家的信息。参数（手机号码）返回值。整条json数据:包括商家表的所有字段.0:无数据
	public void SelectBusinessByMobilePhone(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"SelectBusinessByMobilePhone");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "SelectBusinessByMobilePhone",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
	public void GetQuestion(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetQuestions");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetQuestions",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
//	介绍我。0:更新成功。1更新失败
	public void IntroduceMe(String MobilePhone,String Introduce, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"IntroduceMe");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Introduce", Introduce);
		mWebServiceUtils.sendRequest(rpc, "IntroduceMe",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
//	更新"我的承诺"。0:更新成功。1更新失败
	public void UpdatePromise(String MobilePhone,String Promise, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"UpdatePromise");
		rpc.addProperty("MobilePhone", MobilePhone);
		rpc.addProperty("Promise", Promise);
		mWebServiceUtils.sendRequest(rpc, "UpdatePromise",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
//	根据商家手机号码，获取商家的预订商品信息.0:还未发布商品。1：暂无人预订。json:预订列表
	public void GetPreProduct(String MobilePhone, DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetPreProduct");
		rpc.addProperty("MobilePhone", MobilePhone);
		mWebServiceUtils.sendRequest(rpc, "GetPreProduct",
				HEALTHPASSPORT.URL_OTHER, data);
	}
//	根据专家手机号码和状态获取专家的托管列表.state为“确认”，“关闭”，“解除”，“待专家确认”和“”。
	public void GetTrusteeshipByExpert(String Mobilephone, String state, DefaultJSONData data){
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetTrusteeshipByExpert");
		rpc.addProperty("Mobilephone", Mobilephone);//zhai  此处大小写可能有问题，文档上用小写
		rpc.addProperty("state", state);
		mWebServiceUtils.sendRequest(rpc, "GetTrusteeshipByExpert",
				HEALTHPASSPORT.URL_OTHER, data);
	}
	
	

	/**
	 * 基础配置相关 http://60.174.95.24:82/Healthy/ Config.ashx
	 */

	// 取全部的专业类别和证书类别
	public void GetType(DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "GetType");
		mWebServiceUtils.sendRequest(rpc, "GetType", HEALTHPASSPORT.URL_CONFIG,
				data);
	}

	// 获取全部的商家类型
	public void GetBusiness(DefaultJSONData data) {
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE, "GetBusiness");
		mWebServiceUtils.sendRequest(rpc, "GetBusiness",
				HEALTHPASSPORT.URL_CONFIG, data);
	}
//根据会员手机号码查询病历。参数（会员手机号码,是否是开放的病历）。返回值. IsOpen字段会员传””,专家传true
	public void GetMedicalRecord(String MobilePhone,String IsOpen,DefaultJSONData data ){
		SoapObject rpc = new SoapObject(HEALTHPASSPORT.NAMESPACE,
				"GetMedicalRecord");
		rpc.addProperty("MobilePhone", MobilePhone);//zhai  此处大小写可能有问题，文档上用小写
		rpc.addProperty("IsOpen", IsOpen);
		mWebServiceUtils.sendRequest(rpc, "GetMedicalRecord",
				HEALTHPASSPORT.URL_MAINSERVICE, data);
	}
	
	/**
	 * 获取健康信息
	 * 
	 * @param Identity
	 * @param Password
	 * @return
	 */
	public static HashMap<String, Object> GetEHR(String Identity,
			String Password) {

		LIST_CHECKDATE = new ArrayList();
		HashMap<String, Object> hmap = new HashMap<String, Object>();
		SoapObject request = new SoapObject(SERVER_NAMESPACE, FUC_GETEHR);
		request.addProperty("Identity", Identity);
		request.addProperty("Password", Password);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.bodyOut = request;
		envelope.dotNet = false;
		envelope.setOutputSoapObject(request);

		AndroidHttpTransport ht = new AndroidHttpTransport(SERVER_URL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION + FUC_GETEHR, envelope);
			Log.d("guojie", "ht.call(null, envelope);");
			// SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
			// SoapObject result = (SoapObject) envelope.getResponse();
			Object result = (Object) envelope.getResponse();
			String str_res = result.toString();
			Log.d("guojie", "envelope.getResponse() ==" + result.toString());
			JSONObject rsJson = new JSONObject(str_res);
			String isSuccess = rsJson.getString("IsSuccess");
			if (isSuccess.contains("false")) {
				return null;
			}
			String PersonNum = rsJson.getString("PersonNum");
			Log.d("guojie", "PersonNum===" + PersonNum);
			String Name = rsJson.getString("Name");
			Log.d("guojie", "Name===" + Name);
			String Sex = rsJson.getString("Sex");
			Log.d("guojie", "Sex===" + Sex);
			String Age = rsJson.getString("Age");
			Log.d("guojie", "Age===" + Age);
			String IdCardNo = rsJson.getString("IdCardNo");
			Log.d("guojie", "IdCardNo===" + IdCardNo);
			String Address = rsJson.getString("Address");
			Log.d("guojie", "Address===" + Address);

			HashMap<String, Object> EHRecords = new HashMap<String, Object>();
			JSONArray ehrRecords = rsJson.getJSONArray("EHRRecords");
			for (int j = 0; j < ehrRecords.length(); j++) {
				HashMap<String, Object> EHRecord = new HashMap<String, Object>();
				JSONObject ehrRecord = ehrRecords.optJSONObject(j);
				String CheckSN = ehrRecord.getString("CheckSN");
				String CheckDate = ehrRecord.getString("CheckDate");
				// 设置最近体检日期
				LIST_CHECKDATE.add(CheckDate);
				LASTCHECKDATE = CompareDate(CheckDate);
				String HospName = ehrRecord.getString("HospName");
				JSONArray ehrDetails = ehrRecord.getJSONArray("EHRDetails");
				HashMap<String, Object> EHRMap = new HashMap<String, Object>();
				for (int i = 0; i < ehrDetails.length(); i++) {
					JSONObject ehrDetail = ehrDetails.optJSONObject(i);
					HashMap<String, String> detail = new HashMap<String, String>();
					String ItemSN = ehrDetail.getString("ItemSN");
					String ItemCode = ehrDetail.getString("ItemCode");
					// String ItemNameKey = ehrDetail.getString("ItemNameKey");
					String ItemName = ehrDetail.getString("ItemName");
					String ItemNameAs = ehrDetail.getString("ItemNameAs");
					String ItemValueDesc = ehrDetail.getString("ItemValueDesc");
					String ItemUnit = ehrDetail.getString("ItemUnit");
					String ClinicalMeaning = ehrDetail
							.getString("ClinicalMeaning");
					String NormalValue1 = ehrDetail.getString("NormalValue1");
					String NormalValue2 = ehrDetail.getString("NormalValue2");
					String Tips = ehrDetail.getString("Tips");
					String OrderBy = ehrDetail.getString("OrderBy");
					detail.put("ItemSN", ItemSN);
					detail.put("ItemCode", ItemCode);
					detail.put("ItemName", ItemName);
					detail.put("ItemNameAs", ItemNameAs);
					detail.put("ItemValueDesc", ItemValueDesc);
					detail.put("ItemUnit", ItemUnit);
					detail.put("ClinicalMeaning", ClinicalMeaning);
					detail.put("NormalValue1", NormalValue1);
					detail.put("NormalValue2", NormalValue2);
					detail.put("Tips", Tips);
					detail.put("OrderBy", OrderBy);
					EHRMap.put(ItemName, detail);
				}
				Log.d("guojie", "EHRlist===" + EHRMap.toString());
				EHRecord.put("CheckSN", CheckSN);
				EHRecord.put("CheckDate", CheckDate);
				EHRecord.put("HospName", HospName);
				EHRecord.put("EHRlist", EHRMap);
				// add for test begin
				// String Date1 = "2011-12-06";
				// LIST_CHECKDATE.add(Date1);
				// LASTCHECKDATE = CompareDate(Date1);
				// String Date2 = "2011-12-07";
				// LIST_CHECKDATE.add(Date2);
				// LASTCHECKDATE = CompareDate(Date2);
				// String Date3 = "2011-12-02";
				// LIST_CHECKDATE.add(Date3);
				// LASTCHECKDATE = CompareDate(Date3);
				// EHRecords.put(Date1, EHRecord);
				// EHRecords.put(Date2, EHRecord);
				// EHRecords.put(Date3, EHRecord);
				// add for test end
				EHRecords.put(CheckDate, EHRecord);
			}

			hmap.put("PersonNum", PersonNum);
			hmap.put("Name", Name);
			hmap.put("Sex", Sex);
			hmap.put("Age", Age);
			hmap.put("IdCardNo", IdCardNo);
			hmap.put("Address", Address);
			hmap.put("EHRecords", EHRecords);
			Log.d("guojie", "PersonNum===" + hmap.get("PersonNum"));
			Log.d("guojie", "Name===" + hmap.get("Name"));
			Log.d("guojie", "Age===" + hmap.get("Age"));
			Log.d("guojie", "Sex===" + hmap.get("Sex"));
			Log.d("guojie", "IdCardNo===" + hmap.get("IdCardNo"));
			Log.d("guojie", "Address===" + hmap.get("Address"));
			HashMap<String, Object> alist = (HashMap<String, Object>) hmap
					.get(LIST_CHECKDATE.get(0));
			Log.d("guojie", "CheckDate===" + alist.get("CheckDate"));
			HashMap<String, Object> details = (HashMap<String, Object>) alist
					.get("EHRlist");
			HashMap<String, String> detail = (HashMap<String, String>) details
					.get("体温");
			Log.d("guojie", "ItemSN===" + detail.get("ItemSN"));
			Log.d("guojie", "ItemCode===" + detail.get("ItemCode"));
			Log.d("guojie", "ItemName===" + detail.get("ItemName"));
			Log.d("guojie", "ItemNameAs===" + detail.get("ItemNameAs"));
			Log.d("guojie", "ItemValueDesc===" + detail.get("ItemValueDesc"));
			Log.d("guojie", "ItemUnit===" + detail.get("ItemUnit"));
			Log.d("guojie",
					"ClinicalMeaning===" + detail.get("ClinicalMeaning"));
			Log.d("guojie", "NormalValue1===" + detail.get("NormalValue1"));
			Log.d("guojie", "NormalValue2===" + detail.get("NormalValue2"));
			Log.d("guojie", "Tips===" + detail.get("Tips"));
			Log.d("guojie", "OrderBy===" + detail.get("OrderBy"));
			detail = (HashMap<String, String>) details.get("体重");
			if (detail != null) {
				Log.d("guojie", "detail===" + detail.toString());
			}
			Log.d("guojie", "@@@@@@@@@@@@@@Finish@@@@@@@@@@");

		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

		sortDate();
		for (int i = 0; i < LIST_CHECKDATE.size(); i++) {
			Log.d("guojie", "Date === " + LIST_CHECKDATE.get(i));
		}
		return hmap;
	}

	private static String CompareDate(String date) {
		String[] lastDate = LASTCHECKDATE.split("-");
		Log.d("guojie", "LASTCHECKDATE in CompareDate ===" + LASTCHECKDATE);
		String[] newDate = date.split("-");
		Log.d("guojie",
				"return result in CompareDate "
						+ (Integer.valueOf(newDate[1]) > Integer
								.valueOf(lastDate[1])));
		// Log.d("guojie", "new data =="
		// +Integer.valueOf(newDate[0])+"old date ==="+Integer.valueOf(lastDate[0])
		// );
		Log.d("guojie",
				"return new data in CompareDate =="
						+ Integer.valueOf(newDate[1]) + "old date ==="
						+ Integer.valueOf(lastDate[1]));
		// Log.d("guojie", "new data =="
		// +Integer.valueOf(newDate[2])+"old date ==="+Integer.valueOf(lastDate[2])
		// );
		if (Integer.valueOf(newDate[0]) > Integer.valueOf(lastDate[0])) {
			Log.d("guojie", "return new data for year");
			return date;
		} else if ((Integer.valueOf(newDate[1]) > Integer.valueOf(lastDate[1]))
				&& (Integer.valueOf(newDate[0]) == Integer.valueOf(lastDate[0]))) {
			Log.d("guojie", "return new data for month");
			return date;
		} else if ((Integer.valueOf(newDate[2]) > Integer.valueOf(lastDate[2]))
				&& ((Integer.valueOf(newDate[1]) == Integer
						.valueOf(lastDate[1])) && (Integer.valueOf(newDate[0]) == Integer
						.valueOf(lastDate[0])))) {
			Log.d("guojie", "return new data for day");
			return date;
		}
		Log.d("guojie", "return LASTCHECKDATE in CompareDate==" + LASTCHECKDATE);
		return LASTCHECKDATE;
	}

	private static void sortDate() {
		String[] dates = new String[LIST_CHECKDATE.size()];
		LIST_CHECKDATE.toArray(dates);
		Arrays.sort(dates);
		LIST_CHECKDATE.clear();
		for (int i = 0; i < dates.length; i++) {
			LIST_CHECKDATE.add(dates[dates.length - 1 - i]);
		}
	}

	
	   /**
     * 获得体检项目
     * @return
     */
    public static String GetItems(String Identity,String Password) {
        String str_result = null;
        SoapObject request = new SoapObject(SERVER_NAMESPACE,FUC_GETITEMS);
        request.addProperty("Identity", Identity);
        request.addProperty("Password", Password);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        
        envelope.bodyOut = request;
        envelope.dotNet = false;
        envelope.setOutputSoapObject(request);
        AndroidHttpTransport ht = new AndroidHttpTransport(SERVER_URL);
        ht.debug = true;
        try {
            ht.call(SOAP_ACTION+FUC_GETITEMS, envelope);
//            SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
            Object  result = (Object) envelope.getResponse();
            String str_res = result.toString();
            Log.d("guojie", "envelope.getResponse() =="+result.toString());
            JSONObject rsJson = new JSONObject(str_res);
            
            str_result =rsJson.getString("IsSuccess") + "@";
            if(str_result.contains("true")) {
                
                str_result = str_result+"操作成功";
                JSONArray items = rsJson.getJSONArray("ItemName");
                EHRItems = new String[items.length()];
                for(int i = 0;i<items.length();i++) {
                    EHRItems[i] = String.valueOf(items.get(i));
                    Log.d("guojie", "EHRItems[i]  ===  "+EHRItems[i]);
                }
            } else {
                str_result = str_result
                        +  rsJson.getString("ErrorMessage");
            }
            Log.d("guojie", "UploadPicture ===="+str_result);
        } catch (IOException e) {
            Log.d("guojie", "IOException ===="+e.toString());
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            Log.d("guojie", "XmlPullParserException ===="+e.toString());
            e.printStackTrace();
        } catch(Exception e) {
            Log.d("guojie", "Exception ===="+e.toString());
            e.printStackTrace();
        }
        return str_result;
    }


}
